package com.site.wisdom_construction.controller.personnelModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.personnelModule.EducationProtectiveEquipmentService;
import com.site.wisdom_construction.util.TimeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/3/28
 * @Description
 */
@Api(tags = "入岗教育安全防护用品承诺书接口")
@RestController
@RequestMapping("EducationProtectiveEquipment")
@CrossOrigin
public class EducationProtectiveEquipmentController {
    @Autowired
    private EducationProtectiveEquipmentService educationProtectiveEquipmentService;

    @ApiOperation(value = "增加入岗教育安全防护用品承诺书", notes = "测试数据:")
    @PostMapping("/insertEducationProtectiveEquipment")
    public JsonResult insertEducationProtectiveEquipment(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        map.put("updateDate", TimeUtils.getNowTime());
        int i = educationProtectiveEquipmentService.insertEducationProtectiveEquipment(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入入岗教育安全防护用品承诺书!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入入岗教育安全防护用品承诺书失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除入岗教育安全防护用品承诺书", notes = "测试数据:")
    @PostMapping("/deleteEducationProtectiveEquipment")
    public JsonResult deleteEducationProtectiveEquipment(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = educationProtectiveEquipmentService.deleteEducationProtectiveEquipment(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除入岗教育安全防护用品承诺书!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除入岗教育安全防护用品承诺书失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改入岗教育安全防护用品承诺书", notes = "测试数据:")
    @PostMapping("/updateEducationProtectiveEquipment")
    public JsonResult updateEducationProtectiveEquipment(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        map.put("updateDate", TimeUtils.getNowTime());
        int i = educationProtectiveEquipmentService.updateEducationProtectiveEquipment(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改入岗教育安全防护用品承诺书!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改入岗教育安全防护用品承诺书失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询入岗教育安全防护用品承诺书", notes = "测试数据:")
    @PostMapping("/findEducationProtectiveEquipmentByPage")
    public Page findEducationProtectiveEquipmentByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(educationProtectiveEquipmentService.Total(map));
        page.setItems(educationProtectiveEquipmentService.findEducationProtectiveEquipmentByPage(map));
        return page;
    }

    @ApiOperation(value = "根据工种id查询对应入岗教育安全防护用品承诺书", notes = "测试数据:")
    @PostMapping("/findEducationProtectiveEquipmentByEducationProfessionId")
    public OneDataResult findEducationProtectiveEquipmentByEducationProfessionId(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(educationProtectiveEquipmentService.findEducationProtectiveEquipmentByEducationProfessionId(map));
        return oneDataResult;
    }
}
